// pages/user/mymeal/mymeal.js
var app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    proShow: false,
    mealList: {},
    proList: {},
    meal_id: '',
    info: {
      
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.initApp()
  },

  /**
   * initApp
   */
  initApp: function() {
    let that = this,
        mealList = [],
        i
    wx.showLoading({
      mask: true,
      title: app.globalData.loadText,
    })
    app.getAccessToken(app.getPageUrl(getCurrentPages())).then(function (accessToken) {
      wx.request({
        url: app.globalData.hostAPI + '/v1/customer/setmeal?access_token=' + accessToken,
        success: res => {
          if(res.data.status === 1) {
            for(i in res.data.data.setmeal) {
              if (res.data.data.setmeal[i].setmeal_title != null) {
                mealList.push(res.data.data.setmeal[i])
              }
            }
            that.setData({
              mealList: mealList
            })
          }
          wx.hideLoading()
        }
      })
    })
  },

  selectPro: function(e) {
    let that = this
    wx.navigateTo({
      url: '../../mealconfirm/mealconfirm?meal_id=' + e.currentTarget.dataset.id + '&productID=' + e.currentTarget.dataset.pid + '&hours=' + e.currentTarget.dataset.hours
    })
  },

  /**
   * 关闭
   */
  closePro: function() {
    this.setData({
      proShow: false
    })
  },

  confirmMeal: function(e) {
    let that = this,
        pid = e.currentTarget.id
    wx.navigateTo({
      url: '/pages/mealconfirm/mealconfirm?meal_id=' + that.data.meal_id + '&productID=' + pid,
    })
  }
})